{% extends 'admin/admin_base.html' %}

{% block title %}查看题目 - 后台管理系统{% endblock %}

{% block nav_exams %}active{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>查看题目</h2>
        <div>
            <a href="{{ url_for('admin.exam_view', exam_id=exam._id) }}" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i> 返回试卷
            </a>
        </div>
    </div>

    <!-- 导航按钮组 -->
    <div class="card mb-4">
        <div class="card-body">
            <div class="d-flex justify-content-between">
                <div>
                    <p class="mb-0">
                        <strong>试卷:</strong> {{ exam.name }}
                        <strong class="ms-3">题目:</strong> {{ question_index + 1 }}/{{ total_questions }}
                    </p>
                </div>
                <div class="btn-group">
                    {% if question_index > 0 %}
                    <a href="{{ url_for('admin.question_view', exam_id=exam._id, question_index=question_index-1) }}" class="btn btn-outline-primary">
                        <i class="fas fa-chevron-left"></i> 上一题
                    </a>
                    {% else %}
                    <button class="btn btn-outline-primary" disabled>
                        <i class="fas fa-chevron-left"></i> 上一题
                    </button>
                    {% endif %}
                    
                    {% if question_index < total_questions - 1 %}
                    <a href="{{ url_for('admin.question_view', exam_id=exam._id, question_index=question_index+1) }}" class="btn btn-outline-primary">
                        下一题 <i class="fas fa-chevron-right"></i>
                    </a>
                    {% else %}
                    <button class="btn btn-outline-primary" disabled>
                        下一题 <i class="fas fa-chevron-right"></i>
                    </button>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <!-- 题目卡片 -->
    <div class="card mb-4">
        <div class="card-header bg-primary text-white">
            <h5 class="mb-0">
                {% if question.type == 'single' %}
                    <span class="badge bg-secondary">单选题</span>
                {% elif question.type == 'multiple' %}
                    <span class="badge bg-secondary">多选题</span>
                {% elif question.type == 'boolean' %}
                    <span class="badge bg-secondary">判断题</span>
                {% endif %}
                题目内容
            </h5>
        </div>
        <div class="card-body">
            {% if question.has_image and question.image_path %}
            <div class="text-center mb-3">
                <img src="{{ question.image_path }}" alt="题目图片" class="img-fluid rounded border" style="max-height: 300px;">
            </div>
            {% endif %}
            
            <div class="alert alert-light">
                {{ question.title }}
            </div>
        </div>
    </div>

    <!-- 选项列表 -->
    <div class="card mb-4">
        <div class="card-header bg-primary text-white">
            <h5 class="mb-0">选项和答案</h5>
        </div>
        <div class="card-body">
            {% if question.type == 'single' or question.type == 'multiple' %}
                <div class="list-group">
                    {% for option in question.options %}
                    <div class="list-group-item {% if option.isAnswer %}list-group-item-success{% endif %}">
                        <div class="d-flex align-items-center">
                            {% if question.type == 'single' %}
                                <div class="form-check">
                                    <input class="form-check-input" type="radio" disabled {% if option.isAnswer %}checked{% endif %}>
                                    <label class="form-check-label">
                                        {{ chr_function(65 + loop.index0) }}. {{ option.content }}
                                    </label>
                                </div>
                            {% else %}
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" disabled {% if option.isAnswer %}checked{% endif %}>
                                    <label class="form-check-label">
                                        {{ chr_function(65 + loop.index0) }}. {{ option.content }}
                                    </label>
                                </div>
                            {% endif %}
                            
                            {% if option.isAnswer %}
                            <span class="badge bg-success ms-2">正确答案</span>
                            {% endif %}
                        </div>
                    </div>
                    {% endfor %}
                </div>
            {% elif question.type == 'boolean' %}
                <div class="list-group">
                    <div class="list-group-item {% if question.answer %}list-group-item-success{% endif %}">
                        <div class="form-check">
                            <input class="form-check-input" type="radio" disabled {% if question.answer %}checked{% endif %}>
                            <label class="form-check-label">
                                A. 正确
                            </label>
                            {% if question.answer %}
                            <span class="badge bg-success ms-2">正确答案</span>
                            {% endif %}
                        </div>
                    </div>
                    <div class="list-group-item {% if not question.answer %}list-group-item-success{% endif %}">
                        <div class="form-check">
                            <input class="form-check-input" type="radio" disabled {% if not question.answer %}checked{% endif %}>
                            <label class="form-check-label">
                                B. 错误
                            </label>
                            {% if not question.answer %}
                            <span class="badge bg-success ms-2">正确答案</span>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
